<?PHP
defined('_XR_EXEC') or die();
/**
* 格式化 类 
* by zhoupeng 2012-4-25
*
*/
class format{



	/* 金额格式化 */
	public static function dec($val=0,$deci=2){
		return number_format($val, $deci, '.', '');
	}
	#得到随机密码
	static function getRandPwd($wei=8){
		$a=array('A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
		$b=array('1','2','3','4','5','6','7','8','9');
		$c='';
		$wei = intval($wei);
		for($i=0;$i<$wei;$i++){
			if(rand(0,1)==0 ){
				$c.=$a[rand(0,23)];
			}else{
				$c.=$b[rand(0,8)];
			}
		}
		return $c;
	}

	/* 对象转化成数组 */
	public static function jsonToArray($val){
		if(is_object($val)){
			$val = get_object_vars($val);
		}
		if(is_array($val)){
			foreach ($val as $key => $value) {
				if (is_array($value) || is_object($value)) {
					$val[$key] = self::jsonToArray($value);
				} else {
					//$val[$key] = addslashes($value);
				}
			}
		}
		return $val;
	}

	# 请求变量进行处理函数系列
	static function addslash_deep($val,$force=false) {
		if (!get_magic_quotes_gpc() || $force) {
			if (is_array($val)) {
				foreach ($val as $key => $value) {
					if (is_array($value)) {
						$val[$key] = self::addslash_deep($value,$force);
					} else {
						$val[$key] = addslashes($value);
					}
				}
			}	else {
				$val = addslashes($val);
			}
		}
		return $val;
	}
	static function addslash_json($val)
	{
		return self::addslash_deep(self::jsonToArray($val),true);
	}
	static function stripslashe_deep($val) {
		if (is_array($val)) {
			foreach ($val as $key => $value) {
				if (is_array($value)) {
					$val[$key] = self::stripslashe_deep($value);
				} else {
					$val[$key] = stripslashes($value);
				}
			}
		}	else {
			$val = stripslashes($val);
		}
		return $val;
	}
	/**
	 * 
	 * 截取字符串      shilili   added by 2011-08-24   zhoupeng modify by 2011-9-29
	 * @param unknown_type $s
	 * @param unknown_type $length
	 * @param unknown_type $dot
	 * @param unknown_type $c
	 */
	static function cutstr($s='',$length=10,$dot='...',$c='utf-8'){
		return mb_strimwidth(strip_tags($s),0,intval($length),$dot,$c);
	}
}
?>